import { formatPageInfo } from './tools.js';
// import PageItemEvents from './page_item_events'
import PageItemCpns from './page_item_cpns.js';
import Lxy_page_event_remote from './lxy_page_event_remote.js';
import Lxy_page_event_dialog from './lxy_page_event_dialog.js';
import Lxy_page_event_emit from './lxy_page_event_emit.js';
import Lxy_page_event_custom_func from './lxy_page_event_custom_func.js';
import Lxy_page_event_export_data from './Lxy_page_event_export_data.js';
class PageItem {
	attrs = null; // MainParams 中 除了 'eventList', 'ifRefresh', 'actions', 'globelParams' 的参数
	events = null; // MainParams 中  'eventList'
	others = null; // MainParams 中  'ifRefresh', 'actions', 'globelParams', globelParams: 将key value转换为对象
	constructor(pageInfo, pageCpns) {
		// attrs
		const { attrs, events, others } = formatPageInfo(pageInfo);
		this.attrs = attrs;
		this.events = {};
		this.initEvents(events);
		this.others = others;
		this.components = new PageItemCpns(pageCpns);
		console.log('ddddddddddd', this.components);
	}
	getEvent(eName) {
		console.log('getEvent', this.events);
		if (this.events.hasOwnProperty(eName)) {
			return this.events[eName];
		}
		return null;
	}
	initEvents(events_define) {
		events_define.forEach((e) => {
			switch (e['actionType']) {
				case 0:
					// 自定义
					this.events[e.eName] = new Lxy_page_event_custom_func(e);
					break;
				case 1:
					// 接口
					this.events[e.eName] = new Lxy_page_event_remote(e);
					break;
				case 2:
					// 弹窗
					this.events[e.eName] = new Lxy_page_event_dialog(e);
					break;
				case 3:
					// 执行上级页面函数
					this.events[e.eName] = new Lxy_page_event_emit(e);
					break;
				case 4:
					// 执行上级页面函数
					this.events[e.eName] = new Lxy_page_event_export_data(e);
					break;
				default:
					break;
			}
		});
	}

	getCpn(cpn) {
		return this.components.getCpn(cpn);
	}
}

export default PageItem;
